def copy(file):
    all_row_data = []
    starter_line = ''
    with open(file, 'r') as file:
        # Process the data section
        starter = False
        for line in file:
            if line.startswith('*Y\X'):
                starter = True
                starter_line = line
                continue
            if starter:
                row_data = list(map(float, line.strip().split()[:]))
                all_row_data.append(row_data)

    return all_row_data, starter_line


def multiply_and_write_to_file(file, target):
    data, starter_line = copy(file)
    output_file = f"{file}_output.flm"
    with open(output_file, 'w') as output:
        output.write(starter_line)
        for row_data in data:
            # 将row_data中第二个及以后的元素乘以target
            for i in range(0, len(row_data)):
                if i == 0:
                    continue
                row_data[i] = round(row_data[i] * target, 4)
            #multiplied_data = [num * target for num in row_data]
            output.write(" ".join(map(str, row_data)) + "\n")


if __name__ == "__main__":
    file = "data/I_5_10_8_6_5_s.flm"
    target = 10
    multiply_and_write_to_file(file, target)
